<meta title="编辑类目" args="shopcat" width="500px"/>
<div class="p">
    <form s="valid,form,nda,datac"
          s-data="shopcat"
          id="form" class="form-horizontal"
          method="put"
          action="api/shopcat/{shopcat.id}">
        <table class="table table-bordered table-striped table-hover">
            <tr>
                <td>名称</td>
                <td>
                    <input autocomplete="off" type="text" name="title" s-valid-error="require()" class="form-control input-sm" placeholder="请输入名称">
                </td>
            </tr>
            <tr>
                <td>引用分类</td>
                <td>
                    <div class="p-b-xs">
                        <span name="ref.title" s="" s-data="ref.title" id="refTitle"></span>
                        <a href="javascript:;" s-click="shopcatBatchAdd()" class="btn btn-default btn-xs" >选择</a>
                    </div>
                    <input autocomplete="off" type="text" s="" s-data-filter="'ref.id'" name="refId"
                           id="refId" class="form-control input-sm">
                </td>
            </tr>
            <tr>
                <td>关键字</td>
                <td>
                    <input autocomplete="off" type="text" name="keyword" class="form-control input-sm" placeholder="请输入关键字">
                </td>
            </tr>
            <tr>
                <td>使用关键字查询</td>
                <td>
                    <label class="s-checkbox">
                        <input autocomplete="off" type="checkbox" value="true" name="searchByKeyword" />
                        <span class="s-checkbox-indicator"></span>
                    </label>
                </td>
            </tr>
            <tr>
                <td>状态</td>
                <td>
                    <select class="form-control input-sm pull-right" s="select" name="status" s-build="S.get('/api/enum/valuesMap/core.enums.ShopcatStatus?igNames=DELETED')"></select>
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    S.meta.btns = [
        {
            name: "保存",
            style: "btn btn-primary",
            click: function() {
                return $form.submit().done(function(){
                    S.close(true);
                })
            }
        },
        {
            name: "关闭",
            style: "btn btn-default",
            click: function() {
                S.close();
            }
        }
    ]

    function selectIcon() {
        S.popupOpen("/oss/objects-selector.html", {prefix: 'shopcat-icon'}).done(function(datas) {
            if(datas) {
                var icon = datas[0];
                $icon.data({
                    icon: icon.key,
                    iconUrl: icon.url,
                })
            }
        })
    }

    function selectLocalItemCat($this) {
        S.popupOpen("/top/localItemCatSelector.html").done(function(itemCats) {
            if(itemCats && itemCats.length) {
                var itemCat = itemCats[0]
                $this.node.parent().find(".taobaoCatId").val(itemCat.cid);
                $taobaoCatName.node.html(itemCat.name)
                $taobaoCatNameInput.node.val(itemCat.name)
            }
        })
    }

    function selectTopItemCat($this) {
        S.popupOpen("/top/itemCatSelector.html").done(function(itemCats) {
            if(itemCats && itemCats.length) {
                var itemCat = itemCats[0]
                $this.node.parent().find(".taobaoCatId").val(itemCat.cid);
                $taobaoCatName.node.html(itemCat.name)
                $taobaoCatNameInput.node.val(itemCat.name)
            }
        })
    }

    function selectJdGoodsCategory($this) {
        S.popupOpen("/jos/goodsCategorySelector.html").done(function(cats) {
            if(cats && cats.length) {
                var cat = cats[0]
                $this.node.parent().find(".jdCatId").val(cat.id);
                $jdCatName.node.html(cat.name)
                $jdCatNameInput.node.val(cat.name)
            }
        })
    }
    function selectPddGoodsCat($this) {
        S.popupOpen("/pdd/goodsCatSelector.html").done(function(cats) {
            if(cats && cats.length) {
                var cat = cats[0]
                $this.node.parent().find(".pddCatId").val(cat.catId);
                $pddCatName.node.html(cat.catName)
                $pddCatNameInput.node.val(cat.catName)
            }
        })
    }
    function shopcatBatchAdd() {
        S.popupOpen("/shopcat/shopcatSelector.html", {title: shopcat.title}).done(function(shopcats, path) {
            if(shopcats && shopcats.length) {
                var shopcat = shopcats[0]
                $refTitle.node.text(shopcat.title)
                $refId.node.val(shopcat.id)
            }
        })
    }
</script>